<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	String path = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath()
			+ "/";
	request.setAttribute("path", path);
%>
<base href="<%=path%>"></base>
<title>角色权限配置</title>
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/icon.css">
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
</head>
<body>
<body>

	<!-- 权限管理树 -->
	<ul id="tt" class="easyui-tree"></ul>
	<!-- 树节点右击操作功能 -->
	<div id="mm" class="easyui-menu" style="width: 120px;"
		data-options="onClick:menuHandler">
		<div data-options="iconCls:'icon-add',name:'new'">新增子节点</div>
		<div data-options="iconCls:'icon-edit',name:'update'">修改节点</div>
		<div data-options="iconCls:'icon-remove',name:'delete'">删除节点</div>
		<div data-options="iconCls:'icon-remove',name:'using'">
			<s:radio list="#{'1':'启用','-1':'停用' }" name="psPole.isstart"
				label="启用状态"></s:radio>
		</div>
	</div>
	<!--修改小窗口  -->
	<div id="add_updateDD" class="easyui-dialog" title="修改/新增菜单节点"
		style="width: 400px; height: 200px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true">
		<form id="ff" method="post">
			<div>
				<label>功能名称</label>
				<s:textfield class="easyui-validatebox"
					name="psFunction.functionname"
					data-options="required:true,validType:'isExist'" />

			</div>
			<div>
				<s:textfield name="psFunction.parentid" type="hidden" />
				<s:textfield name="psFunction.createdby" type="hidden" />
			</div>
			<div>
				<label>功能URL</label>
				<s:textfield class="easyui-validatebox" name="psFunction.funcurl"
					data-options="required:true,validType:'isExist'" />

			</div>
			<div>
				<label>状态:</label>
				<s:radio list="#{'1':'启用','-1':'停用' }" name="psFunction.isstart" onchange="toggleFunction"></s:radio>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		function menuHandler(item) {
			if (item.name == 'new') {
				var node = $('#tt').tree('getSelected');
				$('#add_updateDD').dialog({
					buttons : [ {
						text : 'Cancel',
						handler : function() {
							$('#add_updateDD').dialog('close');
						}
					}, {
						text : 'Save',
						iconCls : 'icon-save',
						handler : function() {
							$('#ff').form('load', {
								'psFunction.parentid' : node.id,
								'psFunction.createdby' : 'admin'
							});
							//表单提交
							$('#ff').form({
								url : 'function/addUpdateFunction',
								onSubmit : function(param) {
									
								},
								success : function(data) {
									var data = eval('(' + data + ')');
									showMesage(data.message);
									$('#tt').tree('reload');
								}
							}).submit();

						}
					} ]
				}).dialog('open');

			}
			if (item.name == 'update') {
				var node = $('#tt').tree('getSelected');
				$.ajax({
					url : 'function/findFunction',
					data : {
						'psFunction.id' : node.id
					},
					dataType : 'json',
					success : function(data) {
						//表单数据填充
						$('#ff').form('load', {
							'psFunction.functionname' : data.functionname,
							'psFunction.funcurl' : data.funcurl,
							'psFunction.isstart' : data.isstart,
							'psFunction.parentid' : data.parentid,
							'psFunction.createdby' : data.createdby
						});
					}
				});
				$('#add_updateDD').dialog({
					buttons : [ {
						text : 'Cancel',
						handler : function() {
							$('#add_updateDD').dialog('close');
						}
					}, {
						text : 'Save',
						iconCls : 'icon-save',
						handler : function() {
							//表单提交
							$('#aad_updateFF').form('submit', {
								url : 'function/addUpdateFunction',
								onSubmit : function(psPole) {

								},
								success : function(data) {
									var data = eval('(' + data + ')');
									showMesage(data.message);
									$('#tt').tree('reload');
								}
							});

						}
					} ]
				}).dialog('open');
			}
			if (item.name == 'delete') {
				var node = $('#tt').tree('getSelected');
				var text = node.text;
				$.messager.confirm('确认对话框', '您想要删除' + text + '吗？', function(r) {
					if (r) {
						$.ajax({
							url : 'function/deleteFunction',
							data : {
								'psFunction.id' : node.id
							},
							dataType : 'json',
							success : function(data) {
								//表单数据填充
								showMesage(data.message);
								$('#tt').tree('reload');
							}
						});
						
					}
				});
			}
			if (item.name == 'using') {
				
			}

		}
		function toggleFunction(){
			var node = $('#tt').tree('getSelected');
			$.ajax({
				url : 'function/toggleFunction',
				data : {
					'psFunction.id' : node.id
				},
				dataType : 'json',
				success : function(data) {
					//表单数据填充
					showMesage(data.message);
					$('#tt').tree('reload');
				}
			});
		}
		function showMesage(msg) {
			$.messager.show({
				title : '执行结果',
				msg : msg,
				showType : 'show'
			});
		}
		$(function() {

			$('#tt').tree({
				url : 'function/getFunctionTree',
				checkbox : true

			}).tree({
				onContextMenu : function(e, node) {
					e.preventDefault();
					// 查找节点
					$('#tt').tree('select', node.target);
					// 显示快捷菜单
					$('#mm').menu('show', {
						left : e.pageX,
						top : e.pageY
					});
				}/* ,
								onAfterEdit : function(node) {
									//ajax 提交要修改的节点的详情
									$('#tt').tree('update', {
										target: node.target,
										text: node.text
									});

								} */

			});
		})
	</script>

</body>
</html>